Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

subscriptions-transport-ws

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subscriptions-transport-ws

A websocket transport for GraphQL subscriptions

  • 0.9.19
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
929K
decreased by-42.64%
Maintainers
1
Weekly downloads
 
Created

What is subscriptions-transport-ws?

The subscriptions-transport-ws package is a transport layer for handling GraphQL subscriptions. It uses WebSocket as the communication channel to provide a real-time data exchange between the server and the client. This package is commonly used in the context of GraphQL servers to enable live updates to queries.

What are subscriptions-transport-ws's main functionalities?

Setting up a subscription server

This code sample demonstrates how to set up a GraphQL subscription server using the subscriptions-transport-ws package. It creates a new instance of SubscriptionServer and attaches it to an HTTP server.

const { SubscriptionServer } = require('subscriptions-transport-ws');
const { execute, subscribe } = require('graphql');
const { createServer } = require('http');

const server = createServer((req, res) => {
  res.writeHead(404);
  res.end();
});

server.listen(3000, () => {
  new SubscriptionServer({
    execute,
    subscribe,
    schema: myGraphQLSchema
  }, {
    server: server,
    path: '/subscriptions',
  });
});

Connecting a client to the subscription server

This code sample shows how a client can connect to the subscription server and listen for real-time updates using the SubscriptionClient provided by the subscriptions-transport-ws package.

const { SubscriptionClient } = require('subscriptions-transport-ws');

const client = new SubscriptionClient('ws://localhost:3000/subscriptions', {
  reconnect: true
});

client.request({
  query: `subscription { newMessage { body sender } }`,
  variables: {}
}).subscribe({
  next(data) {
    console.log(data);
  },
  error(err) {
    console.error(err);
  }
});

Other packages similar to subscriptions-transport-ws

FAQs

Package last updated on 08 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc